package net.hn.hnms.biz.plan.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import net.hn.hnms.biz.plan.request.PlanMiningReq;
import net.hn.hnms.biz.plan.service.IPlanMiningService;
import net.hn.hnms.biz.plan.vo.PlanMiningVO;
import net.hn.hnms.sys.common.core.domain.R;
import net.hn.hnms.sys.common.core.domain.ResponsePage;
import net.hn.hnms.sys.common.core.web.controller.BaseController;
import net.hn.hnms.sys.common.log.annotation.Log;
import net.hn.hnms.sys.common.log.enums.BusinessType;
import net.hn.hnms.sys.common.mybatis.core.page.PageQuery;
import net.hn.hnms.sys.common.satoken.config.AutoSetMineCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 回采计划
 *
 * @author zhaoyang
 * @date 2022-08-03
 */

@Api(value = "回采计划模块", tags = {"回采计划"})
@RestController
@RequestMapping("/mining")
public class PlanMiningController extends BaseController {


    @Autowired
    private IPlanMiningService miningPlanService;


    /**
     * 新增回采计划
     */
    @ApiOperation("新增回采计划")
    @SaCheckPermission("plan:mining:add")
    @PostMapping("/add")
    @Log(title = "新增回采计划", businessType = BusinessType.INSERT)
    public R<Void> add(@Validated @RequestBody PlanMiningReq planMining) {
       return toAjax(miningPlanService.insert(planMining));
    }

    /**
     * 删除回采计划
     */
    @ApiOperation("删除回采计划")
    @SaCheckPermission("plan:mining:delete")
    @ApiImplicitParam(name = "idList", value = "要删除的id值,用逗号间隔", required = true, allowMultiple = true, dataType = "String", paramType = "query")
    @DeleteMapping("delete")
    @Log(title = "删除回采计划", businessType = BusinessType.DELETE)
    public R<Void> delete(@RequestParam("idList") List<String> idList) {
        miningPlanService.deleteBatch(idList);
        return R.ok();
    }


    /**
     * 修改回采计划
     */
    @ApiOperation("修改回采计划")
    @SaCheckPermission("plan:mining:update")
    @PutMapping("/update")
    @Log(title = "修改回采计划", businessType = BusinessType.UPDATE)
    public R<Void> update(@Validated @RequestBody PlanMiningReq planMining) {
       miningPlanService.updateById(planMining);
        return R.ok();
    }


    /**
     * 启用/禁用
     */
    @ApiOperation("启用/禁用")
    @SaCheckPermission("plan:mining:status:change")
    @PutMapping("/status/change/{id}/{status}")
    @Log(title = "回采计划启用/禁用", businessType = BusinessType.GRANT)
    public R<Void> changeStatus(@PathVariable("id") String id, @PathVariable("status") Integer status) {
        miningPlanService.changeStatus(id, status);
        return R.ok();
    }

    /**
     * 获取回采计划列表
     */
    @ApiOperation("获取回采计划分页列表")
//    @SaCheckPermission("plan:mining:page")
    @GetMapping("/page")
    @AutoSetMineCode
    public R<ResponsePage<PlanMiningVO>> page(PlanMiningReq planMining, PageQuery pageQuery) {
        return R.ok(miningPlanService.selectPageList(planMining, pageQuery));
    }


    /**
     * 获取回采计划列表
     */
    @ApiOperation("获取回采计划列表")
//    @SaCheckPermission("plan:mining:list")
    @GetMapping("/list")
    public R<List<PlanMiningVO>> list(PlanMiningReq planMining) {
        return R.ok(miningPlanService.selectList(planMining));
    }

    /**
     * 获取回采计划详情
     */
    @ApiOperation("获取回采计划详情")
//    @SaCheckPermission("plan:mining:detail")
    @GetMapping("/{id}")
    public R<PlanMiningVO> detail(@PathVariable("id") String id) {
        return R.ok(miningPlanService.selectDetailById(id));
    }



}
